package org.com.behavioralPattern.mediatorPattern;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jonny
 * @version 1.0
 * @Description:
 * @date 2021/4/27 15:45
 */
public class MarriageAgencyImpl implements MarriageAgency {
    List<Man> manList=new ArrayList<Man>();
    List<Woman> womanList=new ArrayList<Woman>();

    public void register(Person person) {
        if(person.sex== Person.Sex.Male){
            manList.add((Man) person);
        }else {
            womanList.add((Woman) person);
        }
    }

    public void pair(Person person) {
        if(person.sex== Person.Sex.Male){
            for(Woman w: womanList){
                if(w.age==person.requestAge){
                    System.out.println(person.name+"和"+w.name+"配对成功");
                    return;
                }
            }
        }else{
            for (Man m :manList){
                if(m.age==person.requestAge){
                    System.out.println(person.name+"和"+m.name+"配对成功");
                    return;
                }
            }
        }
        System.out.println("没有找到"+person.name+"合适的对象");
    }


}
